package com.itheima.health.mobile.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("mobile/setmeal")
@Slf4j
public class SetmealController {
    @DubboReference
    private SetmealService setmealService;

    /**
     * @Author: 位帅帅
     * @Date: 15:55 2021/1/10
     * @Params: []
     * @RerurnType: com.itheima.health.entity.Result
     * @Description: 查询所有套餐
     */
    @RequestMapping("getSetmeal")
    public Result getSetmeal() {
        //rpc调用查询所有套餐
        List<Setmeal> setmeals = setmealService.findAll();
        log.info("[套餐-查询所有]setmeals: {}", setmeals);
        return new Result(true, MessageConst.GET_SETMEAL_LIST_SUCCESS, setmeals);
    }

    /**
     * @Author: 位帅帅
     * @Date: 16:09 2021/1/10
     * @Params: [id]
     * @RerurnType: com.itheima.health.entity.Result
     * @Description: 根据id查询套餐
     */
    @GetMapping("findById")
    public Result findById(int id) {
        log.info("[套餐-id查询]id: {}", id);
        Setmeal setmeal = setmealService.findById(id);
        log.info("[套餐-id查询]setmeal: {}", setmeal);
        return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS, setmeal);
    }
}
